package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysIncomeMonth;
import com.ruoyi.system.service.ISysIncomeMonthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月收益Controller
 * 
 * @author ruoyi
 * @date 2022-10-30
 */
@RestController
@RequestMapping("/system/month")
public class SysIncomeMonthController extends BaseController
{
    @Autowired
    private ISysIncomeMonthService sysIncomeMonthService;

    /**
     * 查询月收益列表
     */
    @PreAuthorize("@ss.hasPermi('system:month:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysIncomeMonth sysIncomeMonth)
    {
        startPage();
        List<SysIncomeMonth> list = sysIncomeMonthService.selectSysIncomeMonthList(sysIncomeMonth);
        return getDataTable(list);
    }

    /**
     * 导出月收益列表
     */
    @PreAuthorize("@ss.hasPermi('system:month:export')")
    @Log(title = "月收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysIncomeMonth sysIncomeMonth)
    {
        List<SysIncomeMonth> list = sysIncomeMonthService.selectSysIncomeMonthList(sysIncomeMonth);
        ExcelUtil<SysIncomeMonth> util = new ExcelUtil<SysIncomeMonth>(SysIncomeMonth.class);
        util.exportExcel(response, list, "月收益数据");
    }

    /**
     * 获取月收益详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:month:query')")
    @GetMapping(value = "/{incomeId}")
    public AjaxResult getInfo(@PathVariable("incomeId") Long incomeId)
    {
        return AjaxResult.success(sysIncomeMonthService.selectSysIncomeMonthByIncomeId(incomeId));
    }

    /**
     * 新增月收益
     */
    @PreAuthorize("@ss.hasPermi('system:month:add')")
    @Log(title = "月收益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysIncomeMonth sysIncomeMonth)
    {
        return toAjax(sysIncomeMonthService.insertSysIncomeMonth(sysIncomeMonth));
    }

    /**
     * 修改月收益
     */
    @PreAuthorize("@ss.hasPermi('system:month:edit')")
    @Log(title = "月收益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysIncomeMonth sysIncomeMonth)
    {
        return toAjax(sysIncomeMonthService.updateSysIncomeMonth(sysIncomeMonth));
    }

    /**
     * 删除月收益
     */
    @PreAuthorize("@ss.hasPermi('system:month:remove')")
    @Log(title = "月收益", businessType = BusinessType.DELETE)
	@DeleteMapping("/{incomeIds}")
    public AjaxResult remove(@PathVariable Long[] incomeIds)
    {
        return toAjax(sysIncomeMonthService.deleteSysIncomeMonthByIncomeIds(incomeIds));
    }
}
